package com.wymobilearchitecture.study.activity

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import com.example.w_library.log.WLog
import com.wymobilearchitecture.R
import com.wymobilearchitecture.demo.Test
import kotlinx.android.synthetic.main.study_activity_view_tree.*

/**
 * Activity 源码分析使用
 */
class ViewTreeActivity : AppCompatActivity() {

    override fun onStart() {
        super.onStart()

        WLog.e("onStart(): ${btn1.width} --- ${btn1.height}")
        btn1.post {
            WLog.e("onStart():post ${btn1.width} --- ${btn1.height}")
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.study_activity_view_tree)


        WLog.e("onCreate(): ${btn1.width} --- ${btn1.height}")
        btn1.post {
            WLog.e("onCreate():post ${btn1.width} --- ${btn1.height}")
        }
    }


    override fun onResume() {
        super.onResume()
        //获取view宽高
        WLog.e("onResume(): ${btn1.width} --- ${btn1.height}")
        btn1.post {
            WLog.e("onResume():post ${btn1.width} --- ${btn1.height}")
        }
        //多次回调,页面上view树每次发生变化都会进行回调
        btn1.viewTreeObserver.addOnGlobalLayoutListener {
            //不想多次回调可以移除
//            btn1.viewTreeObserver.removeOnGlobalLayoutListener { this }
            WLog.e("onResume():viewTree ${btn1.width} --- ${btn1.height}")
        }


        btn1.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT)

    }

    //Activity 出发 view 渲染的入口在哪里?
    //View 渲染时的渲染流程是怎样的?
    //Activity View 的测绘流程是在哪里开始的?


}